﻿-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[usp_DespieceObtenerHijos]
	@idProducto int,
	@idParte int
AS
BEGIN
	DECLARE @CurrentDespiece hierarchyid
	SELECT @CurrentDespiece = Jerarquia FROM Despiece
	WHERE IdProducto=@idProducto and IdParte=@idParte

	SELECT IdProducto, P.IdParte, P.Descripcion, P.Codigo, Jerarquia, Nivel, Cantidad
	FROM Despiece D
	Inner join Parte P on D.IdParte = P.IdParte 
	WHERE Jerarquia.GetAncestor(1) = @CurrentDespiece;
END